package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.PracticeTask;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 备课练课任务 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-10-09
 */
public interface PracticeTaskMapper extends BaseMapper<PracticeTask> {

    @Select({"<script>",
            "SELECT",
                    "* ",
                    "FROM",
                    "practice_task ",
                    "WHERE",
                    "( deleted = 0 AND year_part = ${yearPart} AND quarter_num = ${quarterNum} AND #{dateNow} BETWEEN task_start_date AND task_end_date ) ",
                    "OR (",
                    "lesson_num IN ( SELECT MAX( lesson_num ) FROM practice_task WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0 )) ",
                    "ORDER BY",
                    "lesson_num ASC ",
                    "LIMIT 1",
    "</script>"})
    public PracticeTask getPracticeTaskNow(@Param("yearPart") Integer yearPart,
                                           @Param("quarterNum") Integer quarterNum,
                                           @Param("dateNow") String dateNow);
}
